package com.easy.controller;

import com.easy.bean.Doctor;
import com.easy.bean.Ward;
import com.easy.common.CommonResult;
import com.easy.dao.IWardDao;
import com.easy.service.IWardService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
public class WardController {
    @Autowired
    IWardDao dao;
    @Autowired
    IWardService wardS;

    @GetMapping("wardname")
    public CommonResult getWardname() {
        List<String> da = wardS.getWardname();
        System.out.println( da); // 输出床位号码
        return CommonResult.success(da);
    }

    @GetMapping("ward")
    public CommonResult getWard(Ward ward, Page page){
        List<Ward> list=wardS.getWard(ward,page);
        int count=wardS.getCount(ward);
        HashMap map=new HashMap();
        map.put("list",list);
        map.put("count",count);
        return CommonResult.success(map);

    }
    @PostMapping("ward")
    public CommonResult addWardJSON(@RequestBody Ward ward){
        System.out.println(ward);
        wardS.addWard(ward);
        ward=wardS.getWardById(ward.getId());
        return CommonResult.success(ward);
    }

    @DeleteMapping("ward/{id}")
    public CommonResult delWard(@PathVariable int id){
        int count=dao.delWard(id);
        if(count>0){
            return CommonResult.success();
        }else {
            return CommonResult.fail();
        }
    }
    @PutMapping("ward")
    public CommonResult editWardJSON(@RequestBody Ward ward ){
        wardS.editWard(ward);
        ward=wardS.getWardById(ward.getId());
        return CommonResult.success(ward);
    }
}
